<?php
namespace App\Services\Fund\CurrencyAccount;
use App\Services\Fund\ValidateCurrencyAccount;
use App\Models\Fund\CurrencyAccount;
use Illuminate\Support\Facades\DB;
class CurrencyAccountLogic
{
   /*protected $name = 'currency_account';
    protected $config = 'db_config_fund';
    private $currencyAccountModel = '\app\serverfund\model\CurrencyAccount';
    private $currencyOptionLogModel = '\app\serverfund\model\CurrencyOptionLog';
    private $currencyFreezeLogModel = '\app\serverfund\model\CurrencyFreezeLog';
    private $currencyUnfreezeLogModel = '\app\serverfund\model\CurrencyUnfreezeLog';
    private $operateReasonModel = '\app\serverfund\model\OperateReason';
    public $scale = 1;*/   //  $scale = 200 ：一个数字币 == 200人民币（单位：分）

    //初始化 比例属性值
   /* public function __construct($data = [])
    {
        isset($data['currency_scale']) && $this->scale = $data['currency_scale'];
    }*/

    /*值为money的积分/余额 转换为多少数字币*/
    /*public function exchange(FundInterface $fundClass, $data): array 
    {
        if($data['money'] == 0){ 
            return auto_success(0);
        }
        if($data['exchange'] == 'Integral'){  //若用积分转化数字币：积分->人民币
            $toFund['app_id'] = $data['app_id'];
            $toFund['exchange'] = 'Integral';
            $toFund['money'] = $data['money'];
            $classPath = '\app\serverfund\logic' . '\\' . 'IntegralAccount';
            $Obj = new $classPath($toFund);
            $toFundRes = logic('\app\serverfund\logic\FundAccount')->exchange($Obj, $toFund);
            if($toFundRes['status'] != SUCCESS_STATUS){
                return $toFundRes;
            }
            $data['money'] = $toFundRes['res']['autoRes'];
        }
        //$res = bcmul( bcdiv($fundClass->scale, $data['currency_scale'], DECIMALS), $data['money'] );  //人民币->数字币
        $res = bcdiv(bcmul($fundClass->scale, $data['money']), $data['currency_scale'], DECIMALS);  //人民币->数字币
        return auto_return($res);
    }*/
    
    // 补全用户数字币日志记录
   /* private function _replenishCurrencyLogInfo(array $save, \app\serverfund\model\CurrencyAccount $info): array
    {
        $save['total'] = $info['total'];
        $save['income'] = $info['income'];
        $save['expend'] = $info['expend'];
        $save['available_currency'] = $info['available_currency'];
        $save['split'] = $info['split'];
        $save['freeze'] = $info['freeze'];
        $save['lock'] = $info['lock'];
        return $save;
    }*/

    // 补全用户数字币日志信息并存到相应数据表中,返回ID
   /* private function _saveCurrencyLogInfo(...$userLogs): int
    {
        $this->model($this->currencyOptionLogModel)->saveAll($userLogs);
        return $this->model($this->currencyOptionLogModel)->getLastInsID();
    }*/

    // 设置已全部解冻的冻结日志表的状态
   /* private function _autoSetFreezeLogStatus(array $data): array
    {
        $where['id'] = $data['freeze_log_id'];
        $where['unfreeze_currency'] = ['exp', '>=currency'];
        $res = $this->model($this->currencyFreezeLogModel)->where($where)->update(['freeze_status'=>'1', 'update_time'=>NOW]);
        return auto_return($res);
    }*/

    // 初始化数字币账户
   /* public function init(array $data): array
    {
        $saveAccount['user_id'] = $data['user_id'];
        $saveAccount['create_ip'] = $data['create_ip'];
        $saveAccount['total'] = 0;
        $saveAccount['income'] = 0;
        $saveAccount['expend'] = 0;
        $saveAccount['available_currency'] = 0;
        $saveAccount['split'] = 0;
        $saveAccount['freeze'] = 0;
        $saveAccount['lock'] = 0;
        $saveAccount['update_ip'] = '';

        $saveLog['user_id'] = $data['user_id'];
        $saveLog['opposite_id'] = SYSTEM_ID;
        $saveLog['app_id'] = $data['app_id'];
        $saveLog['type'] = 'init';
        $saveLog['currency'] = 0;
        $saveLog['total'] = 0;
        $saveLog['income'] = 0;
        $saveLog['expend'] = 0;
        $saveLog['available_currency'] = 0;
        $saveLog['split'] = 0;
        $saveLog['freeze'] = 0;
        $saveLog['lock'] = 0;
        $saveLog['remark'] = '用户[' . $data['user_id'] . ']数字币初始化';
        $saveLog['create_ip'] = $data['create_ip'];
        $saveLog['update_ip'] = '';
        $saveLog['status'] = 1;
        $saveLog['user_info'] = '{}';
        $saveLog['opposite_info'] = '{}';
        $saveLog['other_info'] = $data['other_info'] ?? '{}';

        // 启动事务
        $this->db()->startTrans();
        try{
            $resAccount = $this->model($this->currencyAccountModel)->save($saveAccount);
            $resLog = $this->model($this->currencyOptionLogModel)->save($saveLog);
            // 提交事务
            $this->db()->commit();    
        } catch (\Exception $e) {
            // 回滚事务
            $this->db()->rollback();
            return server_err(null, '数据库异常:' . $e->getMessage());
        }

        return auto_return($resAccount, '成功初始化数字币账户');
    }*/

    # 充值 系统->a
    /*public function prepaid(array $data): array
    {
        // 更改用户数字币
        $whereUpdateUserAccount['user_id'] = $data['user_id'];
        $updateUserAccount['update_ip'] = $data['update_ip'];
        $updateUserAccount['total'] = ['exp', 'total+' . $data['currency']];
        $updateUserAccount['income'] = ['exp', 'income+' . $data['currency']];
        $updateUserAccount['available_currency'] = ['exp', 'available_currency+' . $data['currency']];
        $updateUserAccount['update_time'] = NOW;
        // 更改系统数字币
        $whereUpdateSystemAccount['user_id'] = SYSTEM_ID;
        $updateSystemAccount['update_ip'] = $data['update_ip'];
        $updateSystemAccount['total'] = ['exp', 'total-' . $data['currency']];
        $updateSystemAccount['expend'] = ['exp', 'expend+' . $data['currency']];
        $updateSystemAccount['available_currency'] = ['exp', 'available_currency-' . $data['currency']];
        $updateSystemAccount['update_time'] = NOW;

        // 用户数字币日志(部分)
        $userInfo = json_decode($data['user_info'], true);
        $userAction = isset($userInfo['name']) ? $userInfo['name'] : $data['user_id'];
        $remark = (isset($data['remark']) && $data['remark']) ? '为用户[' . $userAction . ']充值：充值原因：' . $data['remark'] : '为用户[' . $userAction . ']充值';
        $saveUserLog['user_id'] = $data['user_id'];
        $saveUserLog['opposite_id'] = SYSTEM_ID;
        $saveUserLog['app_id'] = $data['app_id'];
        $saveUserLog['type'] = 'prepaid';
        $saveUserLog['currency'] = $data['currency'];
        $saveUserLog['remark'] = $remark;
        $saveUserLog['create_ip'] = $data['update_ip'];
        $saveUserLog['update_ip'] = $data['update_ip'];
        $saveUserLog['status'] = 1;
        $saveUserLog['user_info'] = $data['user_info'];
        $saveUserLog['opposite_info'] = $data['opposite_info'];
        $saveUserLog['other_info'] = $data['other_info'] ?? '{}';
        // 系统数字币日志(部分)
        $saveSystemLog['user_id'] = SYSTEM_ID;
        $saveSystemLog['opposite_id'] = $data['user_id'];
        $saveSystemLog['app_id'] = $data['app_id'];
        $saveSystemLog['type'] = 'prepaid';
        $saveSystemLog['currency'] = -$data['currency'];
        $saveSystemLog['remark'] = $remark;
        $saveSystemLog['create_ip'] = $data['update_ip'];
        $saveSystemLog['update_ip'] = $data['update_ip'];
        $saveSystemLog['status'] = 1;
        $saveSystemLog['user_info'] = $data['user_info'];
        $saveSystemLog['opposite_info'] = $data['opposite_info'];
        $saveSystemLog['other_info'] = $data['other_info'] ?? '{}';


        // 启动事务
        $this->db()->startTrans();
        try{
            // 更改用户数字币
            $resUserAccount = $this->model($this->currencyAccountModel)->where($whereUpdateUserAccount)->update($updateUserAccount);
            // 更改系统数字币
            $resSystemAccount = $this->model($this->currencyAccountModel)->where($whereUpdateSystemAccount)->update($updateSystemAccount);
            // 查询当前用户和系统的数字币状态
            $infoUserAccount = $this->model($this->currencyAccountModel)->lock(true)->where($whereUpdateUserAccount)->find();
            // 查询当前系统的数字币状态
            $infoSystemAccount = $this->model($this->currencyAccountModel)->lock(true)->where($whereUpdateSystemAccount)->find();
            if(is_null($infoUserAccount) || is_null($infoSystemAccount)){
                return verify_err(null, '当前用户或系统用户的数字币账户不存在');
            }
            // 补全用户数字币日志
            $saveUserLog = $this->_replenishCurrencyLogInfo($saveUserLog, $infoUserAccount);
            // 补opposite数字币日志
            $saveSystemLog = $this->_replenishCurrencyLogInfo($saveSystemLog, $infoSystemAccount);
            // 写入数字币日志
            $res = $this->_saveCurrencyLogInfo($saveSystemLog, $saveUserLog);
            // 提交事务
            $this->db()->commit();
        } catch (\Exception $e) {
            // 回滚事务
            $this->db()->rollback();
            return server_err(null, '数据库异常:' . $e->getMessage());
        }

        return auto_return($res, '充值成功');
    }*/

    # 扣除 系统 -> a
    # a->b 转账
   /* public function deduct(array $data): array
    {
        // 更改用户数字币
        $whereUpdateUserAccount['user_id'] = $data['user_id'];
        $whereUpdateUserAccount['available_currency'] = ['EGT', $data['currency']];
        $updateUserAccount['update_ip'] = $data['update_ip'];
        $updateUserAccount['total'] = ['exp', 'total-' . $data['currency']];
        $updateUserAccount['expend'] = ['exp', 'expend+' . $data['currency']];
        $updateUserAccount['available_currency'] = ['exp', 'available_currency-' . $data['currency']];
        $updateUserAccount['update_time'] = NOW;
        // 更改系统数字币
        $whereUpdateSystemAccount['user_id'] = $data['opposite_id'];
        $updateSystemAccount['update_ip'] = $data['update_ip'];
        $updateSystemAccount['total'] = ['exp', 'total+' . $data['currency']];
        $updateSystemAccount['income'] = ['exp', 'income+' . $data['currency']];
        $updateSystemAccount['available_currency'] = ['exp', 'available_currency+' . $data['currency']];
        $updateSystemAccount['update_time'] = NOW;

        // 用户数字币日志(部分)
        $userInfo = json_decode($data['user_info'], true);
        $oppositeInfo = json_decode($data['opposite_info'], true);
        $saveUserLog['user_id'] = $data['user_id'];
        $saveUserLog['opposite_id'] = $data['opposite_id'];
        $saveUserLog['app_id'] = $data['app_id'];
        $saveUserLog['type'] = 'deduct';
        $saveUserLog['currency'] = -$data['currency'];
        $saveUserLog['remark'] = isset($oppositeInfo['name']) ? '转账给用户[' . $oppositeInfo['name'] . ']数字币' : '转账给用户[' . $data['opposite_id'] . ']数字币';
        $saveUserLog['create_ip'] = $data['update_ip'];
        $saveUserLog['update_ip'] = $data['update_ip'];
        $saveUserLog['status'] = 1;
        $saveUserLog['user_info'] = $data['user_info'];
        $saveUserLog['opposite_info'] = $data['opposite_info'];
        $saveUserLog['other_info'] = $data['other_info'] ?? '{}';
        // 系统数字币日志(部分)
        $saveSystemLog['user_id'] = $data['opposite_id'];
        $saveSystemLog['opposite_id'] = $data['user_id'];
        $saveSystemLog['app_id'] = $data['app_id'];
        $saveSystemLog['type'] = 'deduct';
        $saveSystemLog['currency'] = $data['currency'];
        $saveSystemLog['remark'] = isset($userInfo['name']) ? '用户[' . $userInfo['name'] . ']转账给我数字币' : '用户[' . $data['user_id'] . ']转账给我数字币';
        $saveSystemLog['create_ip'] = $data['update_ip'];
        $saveSystemLog['update_ip'] = $data['update_ip'];
        $saveSystemLog['status'] = 1;
        $saveSystemLog['user_info'] = $data['user_info'];
        $saveSystemLog['opposite_info'] = $data['opposite_info'];
        $saveSystemLog['other_info'] = $data['other_info'] ?? '{}';


        // 启动事务
        $this->db()->startTrans();
        try{
            // 查询当前用户和系统的数字币状态
            $infoUserAccount = $this->model($this->currencyAccountModel)->lock(true)->where($whereUpdateUserAccount)->find();
            if(is_null($infoUserAccount)){
                return verify_err(null, '该用户不存在或可用数字币不足');
            }
            // 更改用户数字币
            $resUserAccount = $this->model($this->currencyAccountModel)->where($whereUpdateUserAccount)->update($updateUserAccount);
            // 查询当前系统的数字币状态
            $infoSystemAccount = $this->model($this->currencyAccountModel)->lock(true)->where($whereUpdateSystemAccount)->find();
            if(is_null($infoSystemAccount)){
                return verify_err(null, '当前用户或系统用户的数字币账户不存在');
            }
            // 更改系统数字币
            $resSystemAccount = $this->model($this->currencyAccountModel)->where($whereUpdateSystemAccount)->update($updateSystemAccount);
            // 补全用户数字币日志
            $saveUserLog = $this->_replenishCurrencyLogInfo($saveUserLog, $infoUserAccount);
            // 补opposite数字币日志
            $saveSystemLog = $this->_replenishCurrencyLogInfo($saveSystemLog, $infoSystemAccount);
            // 写入数字币日志
            $this->_saveCurrencyLogInfo($saveSystemLog, $saveUserLog);
            // 提交事务
            $this->db()->commit();
        } catch (\Exception $e) {
            // 回滚事务
            $this->db()->rollback();
            return server_err(null, '数据库异常:' . $e->getMessage());
        }

        return auto_return($infoUserAccount, '扣除成功');
    }*/

    /* 数字币账户 冻结*/
    /*public function freeze(array $data): array 
    {
        //修改账户信息后的查询
        $whereUpdateUser['user_id'] = $data['user_id'];
        $whereUpdateUser['available_currency'] = ['egt',$data['currency']];
        $saveUserAccount['available_currency'] = ['exp', 'available_currency-' . $data['currency']];
        $saveUserAccount['freeze'] = ['exp', 'freeze+' . $data['currency']];
        $saveUserAccount['update_ip'] = $data['update_ip'];
        $saveUserAccount['update_time'] = NOW;
        //补全并添加日志操作记录
        $userInfo = json_decode($data['user_info'], true);
        $addOptionLog['user_id'] = $data['user_id'];
        $addOptionLog['opposite_id'] = $data['opposite_id'];
        $addOptionLog['app_id'] = $data['app_id'];
        $addOptionLog['type'] = 'freeze';
        $addOptionLog['currency'] = -$data['currency'];
        $addOptionLog['remark'] = isset($userInfo['name']) ? '冻结用户' . $userInfo['name'] . '数字币' : '冻结用户' . $data['user_id'] . '数字币';
        $addOptionLog['create_ip'] = $data['update_ip'];
        $addOptionLog['update_ip'] = $data['update_ip'];
        $addOptionLog['user_info'] = $data['user_info'];
        $addOptionLog['opposite_info'] = $data['opposite_info'];
        $addOptionLog['other_info'] = $data['other_info'] ?? '{}';
        //添加冻结日志
        $addFreezeLog['user_id'] = $data['user_id'];
        $addFreezeLog['opposite_id'] = $data['opposite_id'];
        $addFreezeLog['app_id'] = $data['app_id'];
        $addFreezeLog['currency'] = $data['currency'];
        $addFreezeLog['unfreeze_currency'] = 0;
        $addFreezeLog['create_ip'] = $data['update_ip'];
        $addFreezeLog['update_ip'] = $data['update_ip'];
        $addFreezeLog['freeze_status'] = 0;
        $addFreezeLog['user_info'] = $data['user_info'];
        $addFreezeLog['opposite_info'] = $data['opposite_info'];
        $addFreezeLog['type'] = $data['type'];
        $addFreezeLog['obj_id'] = $data['obj_id'];
        $addFreezeLog['freeze_counts'] = $data['freeze_counts'];

        $this->db()->startTrans();
        try{
            $userAccountInfo = $this->model($this->currencyAccountModel)->lock(true)->where($whereUpdateUser)->find();
            if(is_null($userAccountInfo)){
                return verify_err(null, '该用户不存在或可用数字币不足');
            }
            //修改账户信息
            $updateUserRes = $this->model($this->currencyAccountModel)->where($whereUpdateUser)->update($saveUserAccount);
            //补全日志信息并添加
            $addOptionLog = $this->_replenishCurrencyLogInfo($addOptionLog, $userAccountInfo);
            $addFreezeLog['currency_log_id'] = $this->_saveCurrencyLogInfo($addOptionLog);
            //添加冻结日志
            $addFreezeLogRes = $this->model($this->currencyFreezeLogModel)->saveAll([$addFreezeLog]);
            $this->db()->commit();
        }catch(\Exception $e){
            $this->db()->rollback();
            return server_err(null, '数据库异常:' . $e->getMessage() );
        }

        return auto_success($data);
    }*/

    /*管理员冻结用户指定亚数币*/
   /* public function adminFreeze($data): array 
    {
        //添加一条管理员操作原因记录表
        $data['create_ip'] = $data['update_ip'];
        $data['type'] = 'freeze_currency';
        $data['money'] = $data['currency'];
        $res = $this->model($this->operateReasonModel)->allowField(true)->save($data);
        if(!$res){
            return verify_err(null, '添加操作原因记录失败');
        }
        $data['type'] = 'system';
        $data['obj_id'] = $this->model($this->operateReasonModel)->getLastInsID();
        $data['freeze_counts'] = 1;
        return $this->freeze($data);
    }*/

    /*数字币账户 解冻*/
    // public function unfreeze(array $data): array 
    // {
    //     // 检测是否存在冻结日志及数字币是否符合标准
    //     $whereFindUser['user_id'] = $data['user_id'];
    //     $whereFindUser['freeze'] = ['EGT', $data['currency']];
    //     // 检测冻结日志表
    //     /*$whereFreezeLog['id'] = $data['freeze_log_id'];*/
    //     $whereFreezeLog['type'] = $data['type'];
    //     $whereFreezeLog['obj_id'] = $data['obj_id'];
    //     //注释377行的原因： 
    //     //在艺货app_id中用户A转让给用户B一个证书（在艺货中冻结A），但用户B可以在亚数app_id中同意（在亚数中解冻A），故限制app_id会找不到冻结日志记录
    //     //$whereFreezeLog['app_id'] = $data['app_id']; 
    //     $whereFreezeLog['freeze_counts'] = $data['freeze_counts'];
    //     $whereFreezeLog['user_id'] = $data['user_id'];
    //     $whereFreezeLog['status'] = 1;
    //     $whereFreezeLog['freeze_status'] = 0;
    //     // 更改冻结记录表   修改status 
    //     $updateFreezeLog['unfreeze_currency'] = ['exp', 'unfreeze_currency+' . $data['currency']];
    //     $updateFreezeLog['update_time'] = NOW;
    //     // 用户数字币日志(部分)
    //     $updateUserAccount['update_ip'] = $data['update_ip'];
    //     $updateUserAccount['available_currency'] = ['exp', 'available_currency+' . $data['currency']];
    //     $updateUserAccount['freeze'] = ['exp', 'freeze-' . $data['currency']];
    //     $updateUserAccount['update_time'] = NOW;
    //     // 用户数字币日志(部分)
    //     $userInfo = json_decode($data['user_info'], true);
    //     $saveUserLog['user_id'] = $data['user_id'];
    //     $saveUserLog['opposite_id'] = $data['opposite_id'];
    //     $saveUserLog['app_id'] = $data['app_id'];
    //     $saveUserLog['type'] = 'unfreeze';
    //     $saveUserLog['currency'] = $data['currency'];
    //     $saveUserLog['remark'] = isset($userInfo['name']) ? '解冻用户' . $userInfo['name'] . '数字币' : '解冻用户' . $data['user_id'] . '数字币';
    //     $saveUserLog['create_ip'] = $data['update_ip'];
    //     $saveUserLog['update_ip'] = $data['update_ip'];
    //     $saveUserLog['status'] = 1;
    //     $saveUserLog['user_info'] = $data['user_info'];
    //     $saveUserLog['opposite_info'] = $data['opposite_info'];
    //     $saveUserLog['other_info'] = $data['other_info'] ?? '{}';
    //     // 写入解冻记录表
    //     $unfreezeLog['user_id'] = $data['user_id'];
    //     $unfreezeLog['opposite_id'] = $data['opposite_id'];
    //     $unfreezeLog['app_id'] = $data['app_id'];
    //     $unfreezeLog['currency'] = $data['currency'];
    //     /*$unfreezeLog['freeze_log_id'] = $data['freeze_log_id'];*/
    //     $unfreezeLog['create_ip'] = $data['update_ip'];
    //     $unfreezeLog['update_ip'] = $data['update_ip'];
    //     $unfreezeLog['status'] = 1;
    //     $unfreezeLog['user_info'] = $data['user_info'];
    //     $unfreezeLog['opposite_info'] = $data['opposite_info'];
    //     $unfreezeLog['remark'] = $data['remark'] ?? '';
    //     // 启动事务
    //     $this->db()->startTrans();
    //     try{
    //         // 检测用户及可用数字币是否正常
    //         $resFind = $this->model($this->currencyAccountModel)->lock(true)->where($whereFindUser)->find();
    //         if(is_null($resFind)){ return \verify_err(null, '没有符合条件的用户或用户已冻结数字币不足'); }
    //         // 检测冻结日志表
    //         $resFindFreezeLog = $this->model($this->currencyFreezeLogModel)->where($whereFreezeLog)->find();
    //         if(is_null($resFindFreezeLog)){ return \verify_err(null, '没有找到相应的数字币冻结记录'); }
    //         // 冻结相应数字币
    //         $this->model($this->currencyAccountModel)->where(['user_id'=>$data['user_id']])->update($updateUserAccount);
    //         // 查询当前用户的数字币状态
    //         $infoUserAccount = $this->model($this->currencyAccountModel)->lock(true)->where(['user_id'=>$data['user_id']])->find();
    //         // 补全用户数字币日志
    //         $saveUserLog = $this->_replenishCurrencyLogInfo($saveUserLog, $infoUserAccount);
    //         $unfreezeLog['currency_log_id'] = $this->_saveCurrencyLogInfo($saveUserLog);
    //         $unfreezeLog['freeze_log_id'] = $resFindFreezeLog['id'];
    //         // 写入解冻记录表
    //         $this->model($this->currencyUnfreezeLogModel)->isUpdate(false)->save($unfreezeLog);
    //         // 更改冻结记录表
    //         $this->model($this->currencyFreezeLogModel)->where(['id'=>$resFindFreezeLog['id']])->update($updateFreezeLog);
    //         // 将已全部解冻的记录表进行标记
    //         $this->_autoSetFreezeLogStatus(['freeze_log_id'=>$resFindFreezeLog['id']]);
    //         // 提交事务
    //         $this->db()->commit();
    //     } catch (\Exception $e) {
    //         // 回滚事务
    //         $this->db()->rollback();
    //         return server_err(null, '数据库异常:' . $e->getMessage());
    //     }
    //     return auto_success($data);
    // }

    /*账户列表*/
    public function list(array $data): array 
    {
         $query = CurrencyAccount::where('status','=',1);
         $data['keywords'] != '' && $query->where('user_id','like',"%{data['keywords']}%");
         $res = $query->orderBy('id', 'desc')
                      ->paginate($data['list_rows'], null, null, $data['page'])
                      ->toArray();
        return auto_return_page($res, '已找到用户数字币列表数据', '没有用户数字币列表数据');
    }

    /*指定账户的列表*/
    public function listByUserIds(array $data): array 
    {
        $where['status'] = 1;
        $user_ids = explode(",", $data['user_ids']);
        $res = CurrencyAccount::where($where)
                     ->whereIn('user_id',$user_ids)
                     ->orderBy('id', 'desc')
                     ->paginate($data['list_rows'], null, null, $data['page'])
                     ->toArray();
        return auto_return($res, '已找到用户数字币列表数据', '没有用户数字币列表数据');
    }

    //艺货 - 亚数币付款的订单所生成的证书进行提货操作  流程： 
    //解冻亚数币 + 用户转账平台亚数币
    //解冻积分 + 用户转账平台积分
   /* public function affirmPickUpGoods($data): array 
    {
        //开启事务
        $this->db()->startTrans();
        try{
            if($data['currency']){
                //解冻用户亚数币
                $unfreezeRes = $this->unfreeze($data);
                if($unfreezeRes['status'] != SUCCESS_STATUS){
                    $this->db()->rollback();
                    return $unfreezeRes;
                }
                //用户转账平台亚数币
                $transferRes = $this->deduct($data);
                if($transferRes['status'] != SUCCESS_STATUS){
                    $this->db()->rollback();
                    return $transferRes;
                }
            }
            if($data['integral']){  //需要解冻积分 并进行转账给平台
                $IntegralLogic = logic('\app\serverfund\logic\IntegralAccount');
                $unfreezeIntegral = $IntegralLogic->unfreeze($data);
                if($unfreezeIntegral['status'] != SUCCESS_STATUS){
                    $this->db()->rollback();
                    return $unfreezeIntegral;
                }
                $transferIntegralRes = $IntegralLogic->transfer($data);
                if($transferIntegralRes['status'] != SUCCESS_STATUS){
                    $this->db()->rollback();
                    return $transferIntegralRes;
                }
            }
            $this->db()->commit();
        }catch(\Exception $e){
            $this->db()->rollback();
            return server_err(null, '数据库异常:' . $e->getMessage());
        }
        return auto_success($data, '成功进行资金操作');
    }
*/
    /*根据查询条件获取已冻结的最大次数*/
    /*public function getFreezeCounts($data): array 
    {
        $data['user_id'] !== '' && $_where['user_id'] = $data['user_id'];
        //$data['app_id'] !== '' && $_where['app_id'] = $data['app_id'];  //请看第376行注释
        $data['type'] !== '' && $_where['type'] = $data['type'];
        $data['obj_id'] !== '' && $_where['obj_id'] = $data['obj_id'];
        $data['freeze_status'] !== '' && $_where['freeze_status'] = $data['freeze_status'];
        $res = $this->model($this->currencyFreezeLogModel)->where($_where)->max('freeze_counts');
        if(!$res){
            $res = 0;
        }
        return auto_success($res);
    }*/
}